#include <stdio.h>
#include "Util.h"
#include "Const.h"
#include "SelectionSort.h"
#include "InsertionSort.h"
#include "QuickSort.h"
#include "MergeSort.h"
#include "SortFactory.h"

Sort* SortFactory::m_instance = 0;

Sort* SortFactory::Instance(const string& str)
{
	if (!m_instance) {
		delete m_instance;	
	}

	printf("\n%s-------------------------------------------\n", str.c_str());
	if (Util::StrEQ(str, C_STR_INSERTION_DIRECT)) {
		m_instance = new DirectInsertion();

	} else if (Util::StrEQ(str, C_STR_INSERTION_BINARY)) {
		m_instance = new BinaryInsertion();

	} else if (Util::StrEQ(str, C_STR_INSERTION_SHELL)) {
		m_instance = new ShellInsertion();

	} else if (Util::StrEQ(str, C_STR_SELECTION_SIMPLE)) {
		m_instance = new SimpleSelection();

	} else if (Util::StrEQ(str, C_STR_SELECTION_HEAP)) {
		m_instance = new HeapSelection();

	} else if (Util::StrEQ(str, C_STR_SWAP_BUBBLE)) {
		m_instance = new QuickSort();

	} else if (Util::StrEQ(str, C_STR_SWAP_QUICK)) {
		m_instance = new QuickSort();

	} else if (Util::StrEQ(str, C_STR_MERGE)) {
		m_instance = new MergeSort();

	} else {
		fprintf(stderr, "please input type select/");		

	}

	return m_instance;
}

Sort* SortFactory::Instance()
{
	return m_instance;	
}
